#include<stdio.h>
#include<stdlib.h>
#include<winsock2.h>
#include<windows.h>

int main() {
	int port = 8888;
	char *addr ="127.0.0.1";
//	char *addr ="120.79.86.116";
	WORD sockVersion = MAKEWORD(2,2);
	WSADATA data;
	if(WSAStartup(sockVersion, &data) != 0) {
		return 0;
	}

	SOCKET sclient = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if(sclient == INVALID_SOCKET) {
		printf("socket error");
		return 0;
	}

	struct sockaddr_in serAddr;
	serAddr.sin_family = AF_INET;
	serAddr.sin_port = htons(8888);
	serAddr.sin_addr.S_un.S_addr = inet_addr(addr);
	if(connect(sclient, (struct sockaddr *)&serAddr,sizeof(serAddr)) == SOCKET_ERROR) {
		printf("connect error");
		return 0;
	}
	while(1) {
		char recData[255];
		char sendData[255];
		scanf("%s",sendData);
		
		send(sclient, sendData, strlen(sendData), 0);
		int ret = recv(sclient, recData, 255, 0);
		printf("ret=%d",ret);
		if(ret > 0) {
			recData[ret] = 0x00;
			printf("%s",recData);
		}
	}
	closesocket(sclient);
	WSACleanup();


	return 0;
}










